<include file="public@header" />
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" class="pic" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
               style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
             onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
</head>
<body>
<div class="wrap js-check-wrap">
	<ul class="nav nav-tabs">
        <li ><a href="{:url('goods/index')}">品牌列表</a></li>
        <li class="active"><a href="#">添加商品</a></li>
	</ul>
    <form class="form-horizontal js-ajax-form margin-top-20" role="form"  method="post">
        <fieldset>
            <div class="tabbable">
                <div class="tab-content">
                    <div class="tab-pane active" id="A">                       
                        <div class="form-group">
                            <input type="hidden" id="brands" value="">
                            <label for="input-site-g_goodsname" class="col-sm-2 control-label"><span class="form-required">*</span>商品名称</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control"  name="g_goodsname" id="g_goodsname" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>规格</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="format" id="format" style="width: 140px;">
                                    <foreach name="format" item="format">
                                        <option value='{$format.for_guid}'>{$format.f_name}</option>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>原价</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" id="price" name="price" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required"></span>会员价</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" id="vipprice" name="vipprice" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>类别</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="category" id="category" style="width: 140px;">
                                    <foreach name="category" item="category">
                                        <option value='{$category.gc_guid}'>{$category.gc_name}</option>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>品牌</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="brandid" id="brandid" style="width: 140px;">
                                    <foreach name="brand" item="brand">
                                        <option value='{$brand.guid}'>{$brand.name}</option>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_pic" class="col-sm-2 control-label"><span class="form-required"></span>商品图片</label>
                            <div class="info_content" id="Personal">
                            <div class="col-md-6 col-sm-10">
				                   <tr>
				                       <!--  <th>相册</th> -->
				                        <td>
				                            <ul id="photos" class="pic-list list-unstyled form-inline"></ul>
				                            <a href="javascript:uploadMultiImage('图片上传','#photos','photos-item-tpl');"
				                               class="btn btn-default btn-sm">选择图片</a>
				                        </td>
				                    </tr>
				                    </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>库存</label>
                            <div class="col-md-6 col-sm-10">
                                <input type="text" class="form-control" id="stock" name="stock" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required"></span>商品简介</label>
                            <div class="col-md-6 col-sm-10">
                               <textarea class="form-control" name="desc" id="desc" style="height: 80px;"
                                         placeholder="商品简介"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>店铺</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="shop" id="shop" style="width: 140px;">
                                    <foreach name="shop" item="shop">
                                        <option value='{$shop.re_guid}'>{$shop.shop_name}</option>
                                    </foreach>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required"></span>商品状态</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="status" id="status" style="width: 140px;">
                                    <option value='0'>下架</option>
                                    <option value='1'>上架</option>
                                    <option value='-1'>审核中</option>
                                    <option value='-2'>审核失败</option>
                                </select> &nbsp;
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="input-site-g_code" class="col-sm-2 control-label"><span class="form-required">*</span>是否能预约</label>
                            <div class="col-md-6 col-sm-10">
                                <select class="form-control" name="appointment" id="appointment" style="width: 140px;">
                                    <option value='1'>是</option>
                                    <option value='2'>否</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="button" id="sub" class="btn btn-primary js-ajax-submit" data-refresh="1">{:lang('SAVE')}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>
    </form>
    <!-- 预览js -->  
</div>
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>
</body>
<script>
    $('#sub').click(function(){
      var data= new Array();
      $('#prices li').each(function(index)
      {
          var zz=/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
          var price=$(this).find('.price').val();
          var pd=zz.test(price);
          if(pd ==false && price != '')
          {
              alert('请输入纯数字');
              return false;
          }
          var vipprice=$(this).find('.vipprice').val();
          var vip=zz.test(vipprice);
          if(vip ==false && vipprice != '')
          {
              alert('请输入纯数字');
              return false;
          }
          var format=$(this).find('.format').val();
          data.push(format+','+price+','+vipprice);
      });
      var goodsname=$('#g_goodsname').val();
      if(goodsname == '')
      {
          alert('商品名称不能为空！');
          return false;
      }
      var format=$('#format').val();
      var price=$('#price').val();
      var vipprice=$('#vipprice').val();
      var brandid=$('#brandid').val();
      var stock=$('#stock').val();
      var desc=$('#desc').val();
      var statue=$('#status').val();
      var pic=new Array(); ;
      $('#photos li').each(function(index)
        {
            var pics=$(this).find('.pic').val();
           pic.push(pics);
        });
      var shop=$('#shop option:selected').val();
      var appointment=$('#appointment').val();
      var category=$('#category').val();
      $.post("{:url('goods/addpost')}",{shop:shop,format:format,price:price,vipprice:vipprice,goodsname:goodsname,brandid:brandid,stock:stock,desc:desc,statue:statue,pic:pic,category:category,appointment:appointment},function(date){
            if(date == 0)
            {
                alert('添加失败');
            }else{
                alert('添加成功');
                window.location="{:url('goods/index')}";
            }

      },'json')
    })
</script>
</html>